package com.blockmeta.bbs.immodule.adapter;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.blockmeta.bbs.baselibrary.base.adapter.BaseAdapter;
import com.blockmeta.bbs.baselibrary.utils.LoadPicUtil;
import com.blockmeta.bbs.businesslibrary.util.AccountHelper;
import com.blockmeta.bbs.immodule.Constants;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.bean.beaninterface.ICircleEntry;
import com.blockmeta.bbs.businesslibrary.widget.CircleGradeAndKind;
import com.blockmeta.bbs.immodule.corebean.Impl.IMApplicationContext;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

/**
 * @author AirThor
 * @date 2019/3/7.
 */
public class CircleListAdapter extends BaseAdapter<ICircleEntry, BaseViewHolder> {

    public CircleListAdapter(int layoutResId, @Nullable List<ICircleEntry> data) {
        super(layoutResId, data);
    }



    @Override
    public void bindToRecyclerView(RecyclerView recyclerView) {
        super.bindToRecyclerView(recyclerView);
    }

    @Override
    protected void convert(BaseViewHolder helper, ICircleEntry item) {
        boolean isRecommend = item.recommendCircle();
        TextView tvJoinLimit = helper.getView(R.id.tv_join_limit);
        Button btnJoin = helper.getView(R.id.btn_join);
        tvJoinLimit.setVisibility(isRecommend? View.VISIBLE:View.GONE);
        btnJoin.setVisibility(isRecommend? View.VISIBLE:View.GONE);
        String btnStr = IMApplicationContext.getCircleDomainService().getJoinBtnStr(item);
        btnJoin.setText(btnStr);
        btnJoin.setEnabled(!item.getJoinState() && !Constants.LEVEL_NOT_ENOUGH.equals(btnStr));
        //为按钮绑定点击事件
        helper.addOnClickListener(R.id.btn_join);

        ImageView ivLogo = helper.getView(R.id.iv_avatar);
        LoadPicUtil.loadForIm(ivLogo,item.getCircleLogo());

        helper.setText(R.id.tv_circle_name,item.getCircleName());

        helper.setText(R.id.tv_circle_tag,item.getCircleSign());

        helper.setText(R.id.tv_circle_size,item.getCircleSize() + "人");

        helper.setText(R.id.tv_join_limit,item.getCircleJoinLimit());
        helper.setGone(R.id.tv_circle_ismy, item.getCreateById() == AccountHelper.getUidInt());

        CircleGradeAndKind circleGradeAndKind = helper.getView(R.id.cgk_info);
        circleGradeAndKind.setText(item.getCircleGrade(),item.getCircleKind());

        helper.setGone(R.id.iv_im_sign,item.isIdentification());
    }


}
